﻿@page "/sso/userClaim"
@inherits AdminCompontentBase

<PageTitle>
    @T("UserClaim")
</PageTitle>

<DefaultCard>
    <AutoHeight>
        <HeaderContent>
            <div class="d-flex mb-6">
                <SSearch @bind-Value="Search" />
                <MSpacer />
                <SButton Small OnClick="() => AddStandardUserClaimsAsync()" BorderRadiusClass="rounded-lg">
                    <SIcon Size=18 IsDefaultToolTip="false">@IconConstants.Setting</SIcon>
                    <span class="ml-2 btn">@T("Quickly create standard declarations")</span>
                </SButton>
                <SButton Small Class="ml-4" OnClick="() => OpenAddApiResourceDialog()" BorderRadiusClass="rounded-lg">
                    <SIcon Size=18 IsDefaultToolTip="false">@IconConstants.Add</SIcon>
                    <span class="ml-2 btn">@T("Add")</span>
                </SButton>
            </div>
        </HeaderContent>
        <AutoHeightContent>
            <SDataTable
                Height="@("calc(100vh - 288px)")"
                Headers="@_headers" 
                Items="UserClaims" 
                TItem="UserClaimDto" 
                ItemsPerPage="PageSize">
                <HeaderColContent Context="header">
                    <span>@header.Text</span>
                </HeaderColContent>
                <ItemColContent>
                    @switch (context.Header.Value)
                    {
                        case nameof(UserClaimDto.Name):
                            <div class="hover-pointer" @onclick="()=> OpenUpdateApiResourceDialog(context.Item)">
                                <span>@context.Item.Name</span>
                            </div>
                            break;
                        case (nameof(UserClaimDto.Description)):
                            <span class="description">@context.Item.Description</span>
                            break;
                        case nameof(UserClaimDto.UserClaimType):
                            <span>@T(context.Item.UserClaimType.ToString())</span>
                            break;
                        case "Action":
                            <div class="d-flex">
                                <MButton Class="mr-4" Icon OnClick="()=> OpenUpdateApiResourceDialog(context.Item)">
                                    <SIcon Tooltip="@T("Edit")">@IconConstants.Update</SIcon>
                                </MButton>
                                <MButton Class="mr-4" Icon OnClick="()=> OpenRemoveUserClaimDialog(context.Item)">
                                    <SIcon Tooltip="@T("Delete")">@IconConstants.Remove</SIcon>
                                </MButton>
                            </div>
                            break;
                        default:
                            <span>@context.Value</span>
                            break;
                    }
                </ItemColContent>
            </SDataTable>
        </AutoHeightContent>
        <FooterContent>
            <SPagination Class="mt-5" @bind-Page="Page" @bind-PageSize=PageSize Total=Total />
        </FooterContent>
    </AutoHeight>
</DefaultCard>

<AddUserClaimDialog @bind-Visible="AddUserClaimDialogVisible" OnSubmitSuccess=GetUserClaimsAsync />
<UpdateUserClaimDialog @bind-Visible="UpdateUserClaimDialogVisible" UserClaimId=CurrentUserClaimId OnSubmitSuccess=GetUserClaimsAsync />